package cate.common.table.activity.customwarorder.sheet;

import cate.common.table.ESheet;
import cate.common.table.activity.customwarorder.row.CustomWarorderLevelRwdRow;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoteClass("战令等级")
public class CustomWarorderLevelSheet extends ESheet<CustomWarorderLevelRwdRow> {

    @Override
    public String getSheetName() {
        return "等级奖励";
    }


    @NoteField("每一组奖励的经验上限")
    private Map<Integer, Integer> totalExpMax = new HashMap<>();

    @Override
    protected void onLoaded() {
        totalExpMax.clear();
        for (CustomWarorderLevelRwdRow row : this.getList()) {
            int expMax = totalExpMax.getOrDefault(row.group, 0);
            if (row.totalExp > expMax) {
                totalExpMax.put(row.group, row.totalExp);
            }
        }
    }

    /** 根据分组获取奖励 */
    public List<CustomWarorderLevelRwdRow> getRowsByGroup(int group) {
        List<CustomWarorderLevelRwdRow> result = new ArrayList<>();
        for (CustomWarorderLevelRwdRow row : this.getList()) {
            if (row.group == group) {
                result.add(row);
            }
        }
        return result;
    }

    /** 根据分组和等级获取奖励 */
    public CustomWarorderLevelRwdRow getRowByLevel(int group, int level) {
        for (CustomWarorderLevelRwdRow row : this.getList()) {
            if (row.group == group && row.level == level) {
                return row;
            }
        }
        return null;
    }

    public int getMaxExp(int group) {
        return totalExpMax.getOrDefault(group, 0);
    }

}
